package com.scoresystem.dao.proxy;

import java.sql.Connection;
import java.util.List;

import com.scoresystem.dao.IStudentDao;
import com.scoresystem.dao.impl.StudentDaoImpl;
import com.scoresystem.model.StuScore;
import com.scoresystem.model.Student;
import com.scoresystem.model.Subject;
import com.scoresystem.utils.JdbcUtil;

public class StudentDaoProxy implements IStudentDao {
	private IStudentDao dao=null;
	private Connection conn=null;
	
	public StudentDaoProxy()throws Exception{
		conn=JdbcUtil.getInstance().getConnection();
		dao=new StudentDaoImpl(conn);
	}
	
	@Override
	public boolean add(Student student) {
		boolean bool=dao.add(student);
		JdbcUtil.getInstance().free(conn);
		return bool;
	}

	@Override
	public boolean modify(Student student) {
		boolean bool=dao.modify(student);
		JdbcUtil.getInstance().free(conn);
		return bool;
	}

	@Override
	public boolean deleteStudents(String[] stunum) {
		boolean bool=dao.deleteStudents(stunum);
		JdbcUtil.getInstance().free(conn);
		return bool;
	}

	@Override
	public Student findbyName(String stuname) {
		Student student=dao.findbyName(stuname);
		JdbcUtil.getInstance().free(conn);
		return student;
	}

	@Override
	public Student findbyNum(String stunum) {
		Student student=dao.findbyNum(stunum);
		JdbcUtil.getInstance().free(conn);
		return student;
	}

	@Override
	public List<String> getClasses() {
		List<String> list=dao.getClasses();
		JdbcUtil.getInstance().free(conn);
		return list;
	}

	@Override
	public List<String> getMajors() {
		List<String> list=dao.getMajors();
		JdbcUtil.getInstance().free(conn);
		return list;
	}

	@Override
	public List<Student> listbyMajorandClass(String major, String stuclass) {
		List<Student> list=dao.listbyMajorandClass(major, stuclass);
		JdbcUtil.getInstance().free(conn);
		return list;
	}

	@Override
	public List<StuScore> listbyClass(String stuclass) {
		List<StuScore> list=dao.listbyClass(stuclass);
		JdbcUtil.getInstance().free(conn);
		return list;
	}

}
